\paragraph{Contract Methods}

The top level \texttt{def} statement defines the invokable contract methods. A
minimal contract might look like
\begin{simplepy}
def hi() -> str:
    return "hi"
\end{simplepy}

About these methods, two things worth mentioning:
\begin{enumerate}
\item Special Arguments
\item The \texttt{init} method
\end{enumerate}

Method arguments starting with an underscore are special arguments. They are
passed by the runtime, not the invoker. For example,
\begin{simplepy}
def set(key: str, value: Any, _storage: dict[str,Any]) -> None:
    _storage[key] = value

def get(key: str, _storage: dict[str,Any]) -> Any:
    return _storage[key]
\end{simplepy}

The above two methods have the special argument \texttt{\_storage}. This
represents the contract's storage. The runtime will prepare and pass the current
storage to the method. So to invoke the \texttt{set()} method, user only need to
give
\begin{simplejs}
{
    "method" : "set",
    "args" : {
        "k" : "k1",
        "v" : "v1"
    }
}
\end{simplejs}
as the invoke json.

These arguments have special meanings, but they are usally \texttt{dict()}
generated from a json string. In particular we have the following special
arguments:

\begin{itemize}
\item \texttt{\_storage} : the contract's storage. This is just a
  \texttt{dict()} object. And everything written to this object is dumped to
  json and persisted to the blockchain. If the the jsonization of it fails, the
  whole transaction will fail.(So nothing will be written to the blockchain)
\item \texttt{\_tx\_context} : the transaction context. This contains
  information about the current transaction. It is a \texttt{dict()} object with
  the following keys:
  \begin{center}
    \begin{tblr}{XXX}
      \textbf{Key} & \textbf{Type} & \textbf{Description} \\
      \hline
      \texttt{from} & \texttt{str} & the sender's address in hex \\
      \texttt{to} & \texttt{str} & the receiver's address in hex \\
      \texttt{hash} & \texttt{str} & the transaction hash in hex \\
      \texttt{timestamp} & \texttt{int} & the timestamp of the transaction \\
      \hline
    \end{tblr}
  \end{center}
  % \begin{itemize}
  % \item \texttt{from} : the sender's address in hex : \texttt{str}
  % \item \texttt{to} : the receiver's address in hex : \texttt{str}
  % \item \texttt{hash} : the transaction hash in hex : \texttt{str}
  % \item \texttt{timestamp} : the timestamp of the transaction : \texttt{int}
  % \end{itemize}
\end{itemize}

% Local Variables:
% TeX-engine: luatex
% mode: LaTeX
% TeX-command-extra-options: "-shell-escape"
% TeX-master: "m.tex"
% TeX-parse-self: t
% TeX-auto-save: t
% End: